<?php
/**
* This file acts to keep the template versioned and updated.  
* You have to be logged in as news to run this file.  Users trying to access it without having that login will
*	be presented with an error.
* Please note that the URL for this installation of Elgg is automatically loaded into the template when 
*	this file is run.  All instances of {$url} will be replaced with the value specified by 
*	$CFG->wwwroot in the config.php file.
*
**/

// Setup variables.
define("context" , "setup_folio");

$templatename = "Default CGU tCourse Template";

global $CFG,$db;
require("../includes.php");

// See if a user other than news is trying to run this.
if ($USER->username <> 'news') {
	error('You can only run this function if you logged on as "news"');
}

// Start upgrading.
	echo ( 'Beginning update.<br/>');
	echo ( 'The key for this template is ' . folio_getKey() . 
		'.  Be sure to set your config.php file template_id value to this ' .
		'to set it as the default template for all users.<br/>' );
    folio_updateTemplate();
	echo ( 'Finished update.');

/**
* Get the index for the template, or -1 if it isn't present
**/
function folio_getKey() {
	global $CFG;
	global $templatename;

    // Find.
    $templatekey = recordset_to_array(
		get_recordset_sql("SELECT ident, name FROM " . $CFG->prefix . "templates" .
			" WHERE name = '{$templatename}' AND public = 'yes'")
		);
	
    if ( $templatekey ) {
        foreach ($templatekey as $key) {	
			return $key->ident;
		}
	} else {
		// template not found.
		return -1;
	}
}

/** 
* Update existing template, or instead a new one.
**/
function folio_updateTemplate() {
	global $CFG;	
	global $templatename;
	$prefix = $CFG->prefix;
	$db = $CFG->dbname;

	$key = folio_getKey();
	
	// Has the main template file been loaded yet?
	if ( $key == -1 ) {
		// Insert a new template record.
		
		$template = new StdClass;
		$template->name = $templatename;
		$template->owner = 1;
		$template->public = 'yes';
		
		insert_record("templates",$template);
	
		$key = folio_getKey();
	} 

	// Delete existing template detail records.
	delete_records('template_elements','template_id',$key);
	
	// Insert new Page Shell.
	$template = new StdClass;
	$template->name = 'pageshell';
	$template->template_id = $key;
	$template->content = folio_getPageShell();
	
	insert_record("template_elements",$template);
	
	// Insert new CSS.
	$template = new StdClass;
	$template->name = 'css';
	$template->template_id = $key;
	$template->content = folio_getCSS();
	
	insert_record("template_elements",$template);
	
}


function folio_getPageShell() {
	global $CFG;
	$url = $CFG->wwwroot;
	
	// Unused tag?  <p>Welcome {{userfullname}}</p>
	
	return <<< END
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>{{title}}</title>
{{metatags}}
<script type="text/javascript" src="{$url}_customtemplate/util-functions.js"></script>
<script type="text/javascript" src="{$url}_customtemplate/clear-default-text.js"></script>

</head>
<body>

<!-- elgg banner and logo -->
<div id="container"><!-- start container -->
<div id="innerHeadLogo"><!-- start innerHeadLogo -->

<table border="0" cellspacing="0" cellpadding="0" bgcolor="black" style="width:100%; background-color:#000000; padding: 0px 0px 0px 0px;">
	<tr><td>
			<table border="0" cellspacing="0" cellpadding="0" style="height:50px;">
				<tr bgcolor="#000000;">
					<td>
					<a href="http://www.cgu.edu"> 
						<img src="{$url}_customtemplate/images/CGU-Banner.jpg" align=right border=0 />
					</a>
					</td>
					<td width="100%"></td>
					<td valign="bottom">
					<img src="{$url}_customtemplate/images/CGU-Strip.jpg" align=left/>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>

</div><!-- end innerHeadLogo -->
<div id="header"><!-- start header -->
<table border="0" cellspacing="0" cellpadding="0" bgcolor="#990033" style="width:100%; padding: 1px 0px 1px 0px;">
	<tr><td>
	</td><tr>
	</table>
<table border="0" cellspacing="0" cellpadding="0" bgcolor="#000000" style="width:100%; padding: 0px 0px 0px 0px;">
		<table border="0" cellspacing="0" cellpadding="0" class="hdrContent" bgcolor="#000000;" width="100%">
			<tr>
			<td align="right" class="hdrContent" colspan="4">
				<div id="welcome"><!-- start welcome -->
					<!-- <p>Welcome {{userfullname}}</p> -->
					
					<p>
					<a href="{url}">
					CGU Transdisciplinary Course
					</a>
					</p>					
					
				</div><!-- end welcome -->
				<ul id="navigation">
					{{menu}}
				</ul>
			</td>
			</tr>
			<tr>
			<td>
				<div id="statusbar"><!-- start statusbar -->
					{{topmenu}}	
				</div><!-- end statusbar -->
			<form id="searchform" name="searchform"  action="{url}search/all.php">
			<script language="JavaScript" type="text/javascript">
				<!--
				function submitthis()
				{
				  document.searchform.submit() ;
				}
				-->
			</script>
			<input name="tag" type="text" value="Search T-Course" class="cleardefault" style="width: 115px; height: 14px"  />
			<input type="image" border="0" name="" src="{$url}_customtemplate/images/arrows.gif" border="0" alt="">
			&nbsp;
		</form>		
			</td>
			</tr>
		</table>
		</td>
	</tr>
</table>

		</div><!-- end header -->
	
		<div id="sidebar_container">
			<div id="sidebar"><!-- start sidebar -->
				<ul><!-- open sidebar lists -->
				{{sidebar}}
				</ul>
			</div><!-- end sidebar -->
		</div><!-- end sidebar_container -->
		<div id="content_holder"><!-- start contentholder -->
		<div id="maincontent_container"><!-- start main content -->
			{{messageshell}}
			{{mainbody}} 
		</div><!-- end main content -->

	</div><!-- end contentholder -->

		<div class="clearall" />
		<div id="footer"><!-- start footer -->
			<a href="http://elgg.net"><img src="{$url}_templates/elgg_powered.png" 
				alt="Powered by Elgg" title="Powered by Elgg" border="0" /></a>
	</div><!-- end footer -->
	
</div><!-- end container -->
</body>
</html>
	
END;
}

function folio_getCSS() {
	global $CFG;
	$url = $CFG->wwwroot;
	return <<< END

	/*------------------------------------------------------------*
**  Global
**------------------------------------------------------------*/
body {
	background: #FAF4C3 ;
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 75%;
	text-align: center; /* IE Fix */
	margin: 0;
	color: #666;
	}

h1 {
	margin:0px 0px 15px 0px;
	padding:0px;
	font-size:120%;
	font-weight:900;
}


h2 {
	margin:0px 0px 5px 0px;
	padding:0px;
	font-size:100%
}


/* 
acronym { cursor: help; border-bottom: 1px dashed #999; }
a { text-decoration: none; color: #369; border-bottom: 1px dashed #369; }
a:hover { border-bottom: 1px dashed #49515C; color: #49515C; }
*/

a {
	color: blue;	
	text-decoration:none;
	font-size:100%;
}

a:visited {
	color: #8a3207;
}

a:hover {
	color: #753206;
	text-decoration:underline;
}

/*------------------------------------------------------------*
**  Container
**------------------------------------------------------------*/	
#container {
	margin: 0 auto;
	background: #fff;
	border: 1px solid #ddd;
	padding: 0px 2px;
	text-align: left;
	}

/*-----------------------------------------
TOP STATUS BAR 
-------------------------------------------*/

#statusbar {
	float: left;
	background: black;
	padding: 0px 0px 0px 0px;
	color: white;
	font-size:85%;
}

#statusbar a {
	background: black;
	color: white;
	border-bottom: 1px dashed;
	border-color: #990033;
}

#statusbar a:hover  {
	color:  #990033;
	background:black;
	text-decoration: underline;
	 
}

#welcome {
	float: left;
	background: black;
	color: white;
}
#welcome a {
	color: white;
	background: black;
	text-decoration: none;
	border-bottom: none;
}
#welcome a:hover  {
	color:  #990033;
	background:black;
	text-decoration: underline;
	 
}

#welcome p{
	font-weight:normal;
	font-size:110%;
	padding:0 0 0 4px;
	margin:0px;
}

#global_menuoptions {
	color: white;
	font-size:110%;
	text-align: left;
	padding:0px;
	margin:0px;
	float:left;
}

#global_menuoptions ul {
	margin: 0px; 
	padding: 0px;
}

#global_menuoptions li {
	border-color: #000ff;
	margin: 2px; 
	border-right: 0px solid #fff;
	padding: 2px;
	display: inline;
	list-style-type: none;
	text-decoration: dashed; color: white;
}

#global_menuoptions a {
		border-bottom: 1px dashed #49515C; color: white; 
}

#global_menuoptions a:hover {
	text-decoration: underline;
}

/*------------------------------------------------------------*
**  Logo
**------------------------------------------------------------*/		

#innerHeadLogo {
	background: black;
	float: right;
	border-top: 0px solid #fff;
	padding: 0px 0px;
}

#innerHeadLogo  a:link, #innerHeadLogo a:active, #innerHeadLogo a:visited  {
 text-decoration: none;
 font-size: 7pt;
 color: black;
}
/*------------------------------------------------------------*
**  Header
**------------------------------------------------------------*/		
#header {
	background: #000000;
	float: right;
	font-size: 90%;
	border-bottom: 0px solid #fff;
	border-top: 0px solid #fff;
	padding: 0px 0px;
	}	
#header h1 { 	
	margin: 0;
	color: #C6C4C5;
	font-size: 1.8em;
	font-weight: normal;
	cursor: default;
	}	

#header h2 { 	
	margin: 0;
	color: #8D8E90;
	font-size: 1.2em;
	padding-left: 1px;
	cursor: default;
	}	

#header a:hover{
	text-decoration:none;
}

#header form {
	float:right;
	background: black;
	color: white;
	padding-bottom: 0px;
	}
/*------------------------------------------------------------*
**  Nav
**------------------------------------------------------------*/

#navigation {
	background: black; 
	float: right
	border-bottom: 2px solid white;
	margin: 0; 
	padding: 4px 0px 5px 0px;
}
	
#navigation li {
	list-style-type: none;
	display: inline;
	}
	
#navigation a:link, #navigation a:visited {

	background: #990033;
	font-weight: normal;
	padding: 4px 6px;
	margin: 0 2px 0 0;
	border: 0px solid black;
	text-decoration: none;
	color: white;
}

#navigation li a  { 
	text-decoration: none; 
	color: white;
	background-color: #990033;
	border-right: 2px solid white; 
	border-bottom: 0;
	padding: 3px 8px;
	display: inline;
	}

#navigation a:hover  {
	color: #990033;
	background: white;
}

#navigation li a:hover {
	color: #990033;
	background: white;
	}

#navigation a:link.current, #navigation a:visited.current{
	color: #990033;
	background: white;
}

/*------------------------------------------------------------*
**  Side Bar
**------------------------------------------------------------*/
#sidebar {
	float: left;
	width: 18%;
	position: relative;
	line-height: 20px; 
	word-spacing: 2px;
	border-top: 1px solid #ddd;
	border-right: 1px dashed #990033;
	background: #fff ;
	}

/*------------------------------------------------------------*
**  Side Bar & Content
**------------------------------------------------------------*/
#sidebar h2, #content h2 { 
	font-size: 1.1em; 
	color: #49515C; 
	margin: 0 10px 0 0; 
	cursor: default;
	}
#sidebar div { 
	padding: 1px 0 10px 0;  
	border-top: 0px solid #ddd; 
  padding: 10px;
	}
#sidebar ul {
	margin: 0;
	padding: 0;
	list-style: none;
}

#sidebar ul li {
	margin: 10px 0;
	padding-left: 5px;
}

#sidebar p {
    padding:0px;
    margin:0px;
	  	
  }
 
#sidebar #me icon {
  padding:0px;
  margin:0px;
}

#sidebar #me #contents {
  padding:0px;
  margin:0px;

}

#search {
display:none;
}

/*------------------------------------------------------------*
**  Content
**------------------------------------------------------------*/
#maincontent_container {
	float: left;
	width: 70%;
	position: relative;
	margin-left: 15px;
	line-height: 20px; 
	text-align: justify; 
	word-spacing: 2px;
	padding: 10px 0 0 0px ;
	border-top: 1px solid #ddd;
	background: #fff
	}

#maincontent_container a{
    border-bottom:0px;
}

/*------------------------------------------------------------*
**  Footer
**------------------------------------------------------------*/
#footer {
	background: #49515C 
	border-bottom: 5px solid #fff;
	border-top: 10px solid #fff;
	text-align: center;	
	color: #fff;
	font-size: 0.8em;
	padding: 10px;
	line-height: 16px;
	clear: both;
	}
	
#footer a { text-decoration: none; color: #A2AFBF; border-bottom: 1px dashed #A2AFBF; }
#footer a:hover { border-bottom: 1px dashed #fff; color: #fff; }

/*---- Additional classes speciffic to Elgg ---------------*/

/*-----------------------------------------------------------------------
DIV's to help control look and feel - infoholder holds all the profile data
and is always located in within 'maincontentdisplay'

-------------------------------------------------------------------------*/

/*------ holds profile data -------*/
.infoholder {
	border:1px;
	border-color:#eee;
	border-style:solid;
	margin:0 0 5px 0;
}

.infoholder p {
	padding:0 0 0 5px;
}

.infoholder .fieldname h2 {
	border:0;
	border-bottom:1px;
	border-color:#eee;
	border-style:solid;
	padding:5px;
	color:#666;
	background:#fff;
}

.infoholder_twocolumn {
	padding:4px;
	border:1px;
	border-color:#eee;
	border-style:solid;
	margin:0 0 10px 0;
}

.infoholder_twocolumn .fieldname h3{
	color:#666;
	background:#fff;
	border:0px;
	border-bottom:1px;
	border-color:#eee;
	border-style:solid;
}

/*----------- holds administration data---------*/

.admin_datatable {
	border:1px;
	border-color:#eee;
	border-style:solid;
	margin:0 0 5px 0;
}

.admin_datatable p {
	padding:0px;
	margin:0px;
}

.admin_datatable a {
	
}


.admin_datatable td {
	text-align:left;
}

.admin_datatable h3{
	color:#666;
	background:#fff;
}

.admin_datatable h4 {
     padding:0px;
     margin:0px;
}

/*---- header plus one row of content ------*/

.databox_vertical {
	background-color: #F9F9F9;
	color:#000;
	border:1px;
	border-style:solid;
	border-color:#DDD;
	margin:0 0 5px 0;
	padding:5px;
 }

.databox_vertical p{
	padding:0px;
	margin:0px;
	color:black /* #1181AA */;
	background:#fff;
 }

.databox_vertical .fieldname h3 {
	padding:0px;
	margin:0px;
	color:black /* #1181AA */;
	background:#fff;
}

/*------- holds file content ----*/

.filetable {
	background-color: #F9F9F9;
	color:#000;
	border:1px;
	border-style:solid;
	border-color:#DDD;
	margin:0 0 5px 0;
	width:100%;
}

.filetable p{
	padding:0px;
	margin:0px;
	color:#000; /*black /* #1181AA */;*/
	background:#fff;
}

.filetable a{
	
}


.filetable table {
	text-align:left;
}

#edit_files h4 {
	
}


/*------- holds folder content ------*/

.foldertable {
	background-color: #F9F9F9;
	color:#000;
	border:1px;
	border-style:solid;
	border-color:#DDD;
	margin:0 0 5px 0;
	width:100%;
}

.foldertable a{
	
}

.foldertable p{
	padding:0px;
	margin:0px;
	color:black /* #1181AA */;
	background:#fff;
 }

.foldertable table {
	text-align:left;
}

/*------- holds network data ------*/

.networktable {
	
}

/*-------------------------------------------
  INDIVIDUAL BLOG POSTS 
  -------------------------------------------*/


/*------ wraps all blog components ------*/

.weblog_posts {
}

.weblog_posts a{
    border-bottom:0px;
}

.weblog_posts .entry h3 {
	color:black /* #1181AA */;
	background:#fff;
	padding: 0 0 10px 110px;
	font-size:120%;
}

.user {
	float: left;
	margin: 0px;
	padding:0 0 5px 0;
	width: 105px;
	text-align: left;
}

.user a {
	
}

.post {
	margin: 0 0 10px 0;
	padding: 0 0 20px 110px;
	font-family: arial;
}

.post p {
	padding: 0;
	margin: 3px 0 10px 0;
	line-height: 16px;
}

.post ol, .post ul {
	margin: 3px 0 10px 0;
	padding: 0;
}

.post li {
	margin: 0 0 0 30px;
	line-height: 16px;
}

.post ul li {
	list-style-type: square;
}

.post .blog_edit_functions p {
	
}

.post .blog_edit_functions a {
	
}

.post .weblog_keywords p {
	
}

.post .weblog_keywords a {
	
}

.info p {
	padding: 0px;
	margin: 0 0 5px 0;
	color: #666;
	background:#fff;
	font-family: verdana;
	font-weight: normal;
	line-height: 14px;
	text-align: left;
}

.info p a {
	color: #666;
	background:#fff;
	text-decoration: none;
	border-bottom: 0px dotted #666;
	padding-bottom: 0;
}

#comments ol, #comments ul {
	margin: 3px 0 10px 0;
	padding: 0;
}

#comments li {
	margin: 0 0 0 30px;
	line-height: 16px;
}

#comments ul li {
	list-style-type: square;
}

#comments h4 {
	color:black /* #1181AA */;
}

.weblog_dateheader {
	padding: 0px;
	margin: 0 0 5px 0;
	color: #333;
	background:#fff;
	font-weight: normal;
	font-style: italic;
	line-height: 12px;
	border:0px;
	border-bottom: 1px solid #ccc;
}

/*---------------------------------------------
  Your Resources
-----------------------------------------------*/

.feeds {
	border-bottom: 1px dotted #aaaaaa;
	background: transparent ;
}

.feed_content a {
	color:black;
	border:0px;
	border-bottom:1px;
	border-style:dotted;
	border-color:#eee;
}

.feed_content a:hover{
	background:#fff;
	}

.feed_content img {
	border: 1px solid #666666;
	padding:5px;
}

.feed_content h3 {
	padding:0 0 4px 0;
	margin:0px;
}

.feed_content h3 a{
	color:black;
	border:0px;
	border-bottom:1px;
	border-style:dotted;
	border-color:#eee;
}

.feed_content h3 a:hover{
	background:#FCD63F;
	color:#000;
	}

.feed_date h2 {
	font-size:13px;
	line-height: 21px;
	font-weight: bold;
	padding: 5px 10px 5px 5px;
	background: #D0DEDF;
	color:#000;
	text-decoration:none;
}

.via a {
	font-size:90%;
	color:black /* #1181AA */;
	background:#fff;
	border:0px;
	border-bottom:1px;
	border-style:dashed;
	border-color:#ebebeb;
}

.via a:hover {
	background:#ffc;
	color:black /* #1181AA */;
}


/*---------------------------------------
  SYSTEM MESSAGES 
  ---------------------------------------*/

#system_message{ 
	border:1px solid #D3322A;
	background:#F7DAD8;
	color:#000;
	padding:3px 50px;
	margin:0 0 0 20px;
}

#system_message p{
	padding:0px;
	margin:2px;
}


/* -------------  help files -------------*/

.helpfiles ul {
	font-family: arial, helvetica, Tahoma;
	color: #000000;
	background:#fff;
}

.helpfiles h4 {
	
}

/*------ site news for home.php ---------*/

.sitenews {
	background:#ebebeb;
	color:black;
}

.sitenews h2 {
	background:#990033;
	color:#FAC83D;
	padding:0 0 5px 0;
}

/*-------------------------------------
  Input forms
--------------------------------------*/

.textarea {
	border: 1px solid #7F9DB9;
	color:#71717B;
	width: 95%;
	height:200px;
	padding:3px;
}

.medium_textarea {
	width:95%;
	height:100px;
}

.small_textarea {
	width:95%;
}

.keywords_textarea {
	width:95%;
	height:100px;
}


/*--------------------------------------
  MISC
--------------------------------------*/

.clearall {
	padding: 0px;
	clear: both;
	font-size: 0px;
	}

.flagcontent {
	background:#eee;
	color:#000;
	border:1px;
	border-color:#000;
	border-style:solid;
	padding:3px;
}

.flagcontent h5 {
	background:#eee;
	color:black /* #1181AA */;
}
	
		.weblogdateheader {
			font-size: 0.6em;
		}
	.dayofweekbox {
	font-size: 11px;
	font-color: #FFFFFF;
	margin-left: 2px;
	margin-right: 2px;
}    
        .weblogdateheader {
            font-size: 0.6em;
        }
    	

END;
}
?>